using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace CommonAccessLayer
{
	public class usersDAO
{
		public static List<usersBO> GetAll()
		{
			return CBO.FillCollection<usersBO>(DataProvider.getInstance().getAll(TableName.users, PagingHelper.CreateOrder(new OrderObject(usersTable.id, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<usersBO> GetAllC()
		{
			List<usersBO> list = new List<usersBO>();
			if(DataCache.GetCache(CacheName.users) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.users) != null)
					{
						list = (List<usersBO>)DataCache.GetCache(CacheName.users);
					}
					else
					{
			list = CBO.FillCollection<usersBO>(DataProvider.getInstance().getAll(TableName.users, PagingHelper.CreateOrder(new OrderObject(usersTable.id, SortOrder.Desc))));
						DataCache.SetCache(CacheName.users, list);
					}
				}
			}
			else
			{
					list = (List<usersBO>)DataCache.GetCache(CacheName.users);
			}
		return list;
		}
		public static int InsertUpdateDelete(usersBO users, ProviderAction action)
		{
			int rs = DataProvider.getInstance().InsertUpdateDelete(action, StoreProcedureName.InsertUpdateDelete_users, "@" + usersTable.id, users.id,users.nguoidung,users.matkhau, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.users);
			}
			return rs;
		}
        public static usersBO Login(string user,string pass)
        {
            ConnInfo.Db = "VNPT_Common";
            List<usersBO>lst= CBO.FillCollection<usersBO>(
                DataProvider.getInstance().ExecuteReader(StoreProcedureName.spGetUser,user,pass,null,null));
            if (lst.Count > 0)
                return lst[0];
            else
                return null;
        }
	}
}